package com.stylefeng.guns.modular.system.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.modular.system.model.Djg;
import com.stylefeng.guns.modular.system.warpper.DbqWarpper;
import com.stylefeng.guns.modular.system.warpper.GjgWarpper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.Dbq;
import com.stylefeng.guns.modular.system.service.IDbqService;

import java.util.List;
import java.util.Map;

/**
 * 打板圈控制器
 *
 * @author fengshuonan
 * @Date 2018-09-08 23:45:21
 */
@Controller
@RequestMapping("/dbq")
public class DbqController extends BaseController {

    private String PREFIX = "/system/dbq/";

    @Autowired
    private IDbqService dbqService;

    /**
     * 跳转到打板圈首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "dbq.html";
    }

    /**
     * 跳转到添加打板圈
     */
    @RequestMapping("/dbq_add")
    public String dbqAdd() {
        return PREFIX + "dbq_add.html";
    }

    /**
     * 跳转到修改打板圈
     */
    @RequestMapping("/dbq_update/{dbqId}")
    public String dbqUpdate(@PathVariable Integer dbqId, Model model) {
        Dbq dbq = dbqService.selectById(dbqId);
        model.addAttribute("item",dbq);
        LogObjectHolder.me().set(dbq);
        return PREFIX + "dbq_edit.html";
    }

    /**
     * 获取打板圈列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        Page<Dbq> page = new PageFactory<Dbq>().defaultPage();
        List<Map<String, Object>> gdhs = dbqService.selectMaps(page);
        page.setRecords((List<Dbq>) new DbqWarpper(gdhs).warp());
        return super.packForBT(page);
    }

    /**
     * 新增打板圈
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Dbq dbq) {
        dbqService.insert(dbq);
        return SUCCESS_TIP;
    }

    /**
     * 删除打板圈
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer dbqId) {
        dbqService.deleteById(dbqId);
        return SUCCESS_TIP;
    }

    /**
     * 修改打板圈
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Dbq dbq) {
        dbqService.updateById(dbq);
        return SUCCESS_TIP;
    }

    /**
     * 打板圈详情
     */
    @RequestMapping(value = "/detail/{dbqId}")
    @ResponseBody
    public Object detail(@PathVariable("dbqId") Integer dbqId) {
        return dbqService.selectById(dbqId);
    }
}
